package com.kuang.controller;

import com.kuang.mapper.UserMapper;
import com.kuang.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * Author: Zhang Dongwei
 * Date: 2022/7/28 21:50
 */
@RestController
public class UserController {
    @Autowired
    private UserMapper userMapper;

//    查询所有用户
    @GetMapping("/queryUserList")
    public List<User> queryUserList(){
        List<User> userList = userMapper.queryUserList();
        for (User user : userList) {
            System.out.println(user);
        }
        return userList;
    }

//    增加一个用户
    @GetMapping("/addUser")
    public String addUser(){
        userMapper.addUser(new User(6,"老六", "852369741"));
        return "ok";
    }

//    修改一个用户
    @GetMapping("/updateUser")
    public String updateUser(){
        userMapper.updateUser(new User(6, "阿毛", "9874563210"));
        return "ok";
    }

//    根据id删除用户
    @GetMapping("/deleteUser")
    private String deleteUser(){
        userMapper.deleteUser(6);
        return "ok";
    }
}
